FROM golang:1.15-alpine as builder

WORKDIR /app

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk add --repository https://mirrors.ustc.edu.cn/alpine/v$(cat /etc/alpine-release | cut -c1-3)/main/ --no-cache --virtual .build-deps \
    build-base ca-certificates git make bash yarn nodejs

# RUN go env -w GO111MODULE=on && \
#     go env -w GOPROXY=https://goproxy.cn,direct


ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct

COPY makefile .
COPY go.mod .
COPY . .

RUN yarn config set ignore-engines true \
    && make install-vue \
    && make build-vue \
    && make statik \
    && CGO_ENABLED=0 make gocron

FROM alpine:3.12

RUN apk add --no-cache ca-certificates tzdata \
    && addgroup -S app \
    && adduser -S -g app app

RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

WORKDIR /app

COPY --from=builder /app/bin/gocron .

RUN chown -R app:app ./

EXPOSE 5920

USER app

ENTRYPOINT ["/app/gocron", "web"]